button: Add back visual feedback for keynav
authorMatthias Clasen <mclasen@redhat.com>
Thu, 1 Apr 2021 22:36:23 +0000 (18:36 -0400)
committerMatthias Clasen <mclasen@redhat.com>
Thu, 1 Apr 2021 22:38:11 +0000 (18:38 -0400)
We lost the visual feedback for activating a button
via Space or Enter when the :active pseudo-state became
managed. Bring it back with a style class.

Fixes: #3813
gtk/gtkbutton.c
gtk/theme/Adwaita/_common.scss

index 3b2aad8f342569a5acb22d8fd3dc3d3e35389d2f..1acc35d5695b579eb6e2cbe4805551e9069d6b58 100644 (file)
@@ -39,6 +39,8 @@
  * `GtkButton` has a single CSS node with name button. The node will get the
  * style classes .image-button or .text-button, if the content is just an
  * image or label, respectively. It may also receive the .flat style class.
+ * When activating a button via the keyboard, the button will temporarily
+ * gain the .keyboard-activating style class.
  *
  * Other style classes that are commonly used with `GtkButton` include
  * .suggested-action and .destructive-action. In special cases, buttons
@@ -780,6 +782,8 @@ gtk_real_button_activate (GtkButton *button)
     {
       priv->activate_timeout = g_timeout_add (ACTIVATE_TIMEOUT, button_activate_timeout, button);
       g_source_set_name_by_id (priv->activate_timeout, "[gtk] button_activate_timeout");
+
+      gtk_widget_add_css_class (GTK_WIDGET (button), "keyboard-activating");
       priv->button_down = TRUE;
     }
 }
@@ -790,6 +794,8 @@ gtk_button_finish_activate (GtkButton *button,
 {
   GtkButtonPrivate *priv = gtk_button_get_instance_private (button);
 
+  gtk_widget_remove_css_class (GTK_WIDGET (button), "keyboard-activating");
+
   g_source_remove (priv->activate_timeout);
   priv->activate_timeout = 0;
 
index c5baa58518626229affd82563e5c191eccbff36f..ea4c31f6d1338e1ea426670b9dbc4dec1ffb2611 100644 (file)
@@ -492,6 +492,7 @@ button {
       -gtk-icon-filter: brightness(1.2);
     }
 
+    &.keyboard-activating,
     &:active,
     &:checked {
       @include button(active);